# -*- coding:utf-8 -*-
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector

from rentscrapy.items import DemoItem

class DemoSpider(BaseSpider):
    name = 'Demo'
    start_urls = ['http://www.tcmap.com.cn/beijing/',
                  'http://www.tcmap.com.cn/jiangsu/']

    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        trs = hxs.select('//div[@id="page_left"]/table[@bgcolor="cccccc"]/tr[@bgcolor="#f8f8f8" or @bgcolor="#ffffff"]')
        items = []
        for tr in trs:
            item = DemoItem()
            item['city'] = tr.select('td/strong/a/text()').extract()
            item['tel_code'] = tr.select('td[4]/text()').extract()
            item['id_code'] = tr.select('td[5]/text()').extract()
            items.append(item)
        return items



